import { urlService, ApiService } from './api';
import { StorageService } from './sotrage/storage.service';
import { CoreModule } from './core.module';
import { Injectable } from '@angular/core';
import { I18nService } from './i18n/i18n.service';
import { Observable } from 'rxjs';

// 全局map
@Injectable({
    providedIn: CoreModule,
})
export class Global {

    getSelectMap(name): any {
        let map: any = {
            '标志': [{ key: 0, text: '西药剂型' }, { key: 1, text: '中药剂型' }],
            '中西草标志': [{ key: 0, text: '全部' }, { key: 1, text: '西药' }, { key: 2, text: '中药' }, { key: 3, text: '草药' }],
        }
        return map[name];
    }
    /**
     * 登录前获取唯一身份标识用于图形验证码获取
     */
    async getImageVerifyCodeId() {
        if (this.sto.get('imageVerifyCodeId')) {
			let data = await new Promise((r,s)=>{
				r({ imageVerifyCodeId: this.sto.get('imageVerifyCodeId'), bool: true });
			});
            return data;
        } else {
			let data = await this.api.post('生成图形验证码唯一id', {});
			this.sto.set('imageVerifyCodeId', data['status'] == 0 ? data['data']['imageVerifyCodeId'] : false);
			return { imageVerifyCodeId: data['data']['imageVerifyCodeId'], bool: true };
        }
    }

    getI18n(arr):any {
        this.i.get(arr).subscribe(res => {
            return res;
        })
    };

    constructor(
        private i: I18nService,
        private api: ApiService,
        private sto: StorageService,
    ) { };
}